﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Drawing;
using System.Drawing.Imaging;

namespace MediaClient.Common
{
    public class Utility
    {
        public static XmlNodeList GetNodes(string xmlFile, string xpath)
        {
            XmlNodeList nodeList = null;
            try
            {
                XmlDocument xml = new XmlDocument();
                xml.Load(xmlFile);
                nodeList = xml.DocumentElement.SelectNodes(xpath);
            }
            catch (Exception myE)
            {
                throw myE;
            }
            return nodeList;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="width">1920</param>
        /// <param name="heigth">540</param>
        /// <param name="waterMarker"></param>
        /// <param name="imgPath"></param>
        public static void GenerateWaterMarkerImage(int width,int heigth, string waterMarker, string imgPath)
        {
            if (System.IO.File.Exists(imgPath) == true)
                System.IO.File.Delete(imgPath);
            Bitmap bt = new Bitmap(width, heigth, PixelFormat.Format24bppRgb);
            Graphics g = Graphics.FromImage(bt);
            Font fn1 = new Font("Tahoma", 100, FontStyle.Bold);
            g.Clear(Color.White);
            g.DrawString(waterMarker, fn1, Brushes.Black, new PointF(150, Convert.ToSingle(heigth*0.4)));

            string path = System.IO.Path.GetDirectoryName(imgPath); ;
            if (System.IO.Directory.Exists(path) == false)
                System.IO.Directory.CreateDirectory(path);
            bt.Save(imgPath, ImageFormat.Bmp);
            //释放位图缓存
            bt.Dispose();   
        }
    }
}
